package main

import (
	"fmt"
	"time"
)

func backspaceCompare(s string, t string) bool {
	// 两个字符串转换为切片
	sliceS := []byte{}
	sliceT := []byte{}

	// fmt.Println(sliceS)
	// fmt.Println(sliceT)

	//处理s字符串的#号
	for i := 0; i < len(s); i++ {
		if s[i] != '#' {
			sliceS = append(sliceS, s[i])
		}
		if s[i] == '#' {
			if len(sliceS) == 0 {
				continue
			} else {
				sliceS = append(sliceS[:len(sliceS)-1])
			}
		}
	}
	// fmt.Printf("%s\n", sliceS)

	//处理T字符串的#号
	fmt.Println(t)
	for i := 0; i < len(t); i++ {
		if t[i] != '#' {
			sliceT = append(sliceT, t[i])
		}
		if t[i] == '#' {
			// fmt.Printf("%s\n", sliceT)
			if len(sliceT) == 0 {
				continue
			} else {
				sliceT = append(sliceT[:len(sliceT)-1])
			}
		}
	}
	// fmt.Printf("%s\n", sliceT)

	//比较两个字符串
	slen := len(sliceS)
	tlen := len(sliceT)
	if slen != tlen {
		return false
	}

	for i := 0; i < slen; i++ {
		if sliceS[i] != sliceT[i] {
			return false
		}
	}

	return true
}

func main() {
	start := time.Now()
	s := "xywrrmp"
	t := "xywrrmu#p"
	result := backspaceCompare(s, t)
	cost := time.Since(start)
	fmt.Println(result)
	fmt.Println(cost)

}
